﻿Imports System
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Search.Interop
Imports System.ComponentModel
Namespace C4F.DevKit.DesktopSearch

#Region "Enumerations"
    ''' <summary>
    '''  Represents different types of file.
    ''' </summary>
    Public Enum FileType
        ''' <summary>
        '''  Represents All files. Default value for FileType enumeration is “All”. 
        ''' </summary>
        All = 0
        ''' <summary>
        '''  Represents Ms office files. Standard extension covered for office files are "xls" , "xlsx" , "ppt", "doc", "docx", "one","accdb".
        ''' </summary>
        MSOffice = 1
        ''' <summary>
        '''  Represents Ms word document.
        ''' </summary>
        MSWord = 2
        ''' <summary>
        '''  Represents Ms excel document.
        ''' </summary>
        MSExcel = 3
        ''' <summary>
        '''  Represents Ms power point document.
        ''' </summary>
        MSPowerPoint = 4
        ''' <summary>
        '''  Represents text files.
        ''' </summary>
        Text = 5
        ''' <summary>
        '''  Represents Html files.
        ''' </summary>
        Html = 6
        ''' <summary>
        '''  Represents Xml files.
        ''' </summary>
        Xml = 7
        ''' <summary>
        ''' Represents C# files.
        ''' </summary>
        CSharp = 8
        ''' <summary>
        '''  Represents Vb files.
        ''' </summary>
        VB = 9
    End Enum
    ''' <summary>
    '''  Represents possible values of date filter for emails.
    ''' </summary>
    Public Enum EmailDateFilter
        ''' <summary>
        ''' No filter specified for different dates of email.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Compare specified date with date when email is sent.
        ''' </summary>
        DateSent = 1
        ''' <summary>
        '''  Compare specified date with date when email is received.
        ''' </summary>
        DateReceived = 2
        ''' <summary>
        '''  Compare specified date with date when email is last modified.
        ''' </summary>
        DateModified = 3
        ''' <summary>
        '''  Compare specified date with date when email is created.
        ''' </summary>
        DateCreated = 4
    End Enum
    ''' <summary>
    '''  Represents different options for date comparision.
    ''' </summary>
    Public Enum DateCompareOption
        ''' <summary>
        '''  Date comparison with specified date is not performed.
        ''' </summary>
        Any = 0
        ''' <summary>
        '''  Date same as specfied date.
        ''' </summary>
        [Is] = 1
        ''' <summary>
        ''' Date before specified date.
        ''' </summary>
        Before = 2
        ''' <summary>
        ''' Date after specified date.
        ''' </summary>
        After = 3
    End Enum
    ''' <summary>
    '''  Represents different options for item size comparision.
    ''' </summary>
    Public Enum SizeCompareOption
        ''' <summary>
        '''  No comaparsion with specified size of item.
        ''' </summary>
        Any = 0
        ''' <summary>
        '''  Item size is same as specified size.
        ''' </summary>
        Equals = 1
        ''' <summary>
        '''  Item size is less than specified size.
        ''' </summary>
        IsLessThan = 2
        ''' <summary>
        '''  Item size is greater than specified size.
        ''' </summary>
        IsGreaterThan = 3
    End Enum
    ''' <summary>
    '''  Represents possible values of date filter for picture files.
    ''' </summary>
    Public Enum PictureDateFilter
        ''' <summary>
        ''' No filter specified for different dates of picture.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Compare specified date with date when picture file is taken.
        ''' </summary>
        DateTaken = 1
        ''' <summary>
        '''  Compare specified date with date when picture file is last modified.
        ''' </summary>
        DateModified = 2
        ''' <summary>
        '''  Compare specified date with date when picture file is created.
        ''' </summary>
        DateCreated = 3
    End Enum
    ''' <summary>
    '''  Represents possible values of date filter for music files.
    ''' </summary>
    Public Enum MusicDateFilter
        ''' <summary>
        ''' No filter specified for different dates of music files.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Compare specified date with date when picture file is last modified.
        ''' </summary>
        DateModified = 1
        ''' <summary>
        '''  Compare specified date with date when picture file is created.
        ''' </summary>
        DateCreated = 2
    End Enum
    ''' <summary>
    '''  Represents possible values of date filter for all files.
    ''' </summary>
    Public Enum FileDateFilter
        ''' <summary>
        ''' No filter specified for different dates of files.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Compare specified date with date when file is last modified.
        ''' </summary>
        DateModified = 1
        ''' <summary>
        '''  Compare specified date with date when file is created.
        ''' </summary>
        DateCreated = 2
    End Enum
    ''' <summary>
    '''  Represents attributes of file.
    ''' </summary>
    <Flags()> _
    Public Enum FileAttributes As Byte
        ''' <summary>
        '''  No attribute is assigned to file.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Read-only file attribute.
        ''' </summary>
        [ReadOnly] = 1
        ''' <summary>
        '''  Archive file attribute.
        ''' </summary>
        Archive = 32
        ''' <summary>
        '''  Hidden file attribute.
        ''' </summary>
        Hidden = 2
        ''' <summary>
        ''' System file attribute.
        ''' </summary>
        System = 4
        ''' <summary>
        ''' Sub-directory entry attribute.
        ''' </summary>
        SubDirectory = 16
    End Enum
    ''' <summary>
    '''  Represents priority of email.
    ''' </summary>
    Public Enum EmailPriority As Byte
        ''' <summary>
        ''' Email with any priority. “All” is default value for email priority.
        ''' </summary>
        None = 0
        ''' <summary>
        '''  Email with normal importance.
        ''' </summary>
        Normal = 3
        ''' <summary>
        '''  Email with high importance.
        ''' </summary>
        High = 5
        ''' <summary>
        '''  Email with low importance.
        ''' </summary>
        Low = 1
    End Enum
#End Region

#Region "DesktopSearchManager class"
    ''' <summary>
    ''' Provide wrapper over windows desktop search assembly.
    ''' </summary>
    <ToolboxItem(True), ToolboxBitmap(GetType(DesktopSearchManager))> _
    Public Class DesktopSearchManager
        Inherits Component

#Region "Private Members"
        Private systemDbconnection As OleDbConnection
#End Region

#Region "Private Methods"
        ''' <summary>
        ''' Executes the search query.
        ''' </summary>
        ''' <param name="searchQuery">Search query.</param>
        ''' <returns>Object of OleDbDataReader class.</returns>
        Private Function GetQueryResponse(ByVal searchQuery As String) As OleDbDataReader
            'ConnectionString for connection to system database.
            Dim systemConnectionString As String = "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
            systemDbconnection = New OleDbConnection(systemConnectionString)
            systemDbconnection.Open()
            Dim systemCommand As OleDbCommand = New OleDbCommand()
            systemCommand.Connection = systemDbconnection
            systemCommand.CommandText = searchQuery
            Dim systemDbreader As OleDbDataReader
            systemDbreader = systemCommand.ExecuteReader()
            Return systemDbreader
        End Function
        ''' <summary>
        '''  Gets reference of CSearchQueryHelper Interface.
        ''' </summary>
        ''' <returns>Object of CSearchQueryHelper.</returns>
        Private Shared Function InitializeSearch() As CSearchQueryHelper
            Dim manager As CSearchManager = New CSearchManagerClass()
            Dim catalogManager As CSearchCatalogManager = manager.GetCatalog("SystemIndex")
            Dim queryHelper As CSearchQueryHelper = catalogManager.GetQueryHelper()
            Return queryHelper
        End Function
        ''' <summary>
        '''  Gets type of file to be searched.
        ''' </summary>
        ''' <param name="fileSearchCriteria">Object of FileSearchCriteria class.</param>
        ''' <returns>Object of string.</returns>
        Private Shared Function GetFileTypeQuery(ByVal fileSearchCriteria As FileSearchCriteria) As String
            Dim searchQuery As String = String.Empty
            Select Case fileSearchCriteria.FileType
                Case FileType.All
                    Exit Select
                Case FileType.CSharp
                    searchQuery = WindowsDesktopSearchResource.CSharp
                    Exit Select
                Case FileType.Html
                    searchQuery = WindowsDesktopSearchResource.Html
                    Exit Select
                Case FileType.MSExcel
                    searchQuery = WindowsDesktopSearchResource.MSExcel
                    Exit Select
                Case FileType.MSOffice
                    searchQuery = WindowsDesktopSearchResource.MSOffice
                    Exit Select
                Case FileType.MSPowerPoint
                    searchQuery = WindowsDesktopSearchResource.MSPowerPoint
                    Exit Select
                Case FileType.MSWord
                    searchQuery = WindowsDesktopSearchResource.MSWord
                    Exit Select
                Case FileType.Text
                    searchQuery = WindowsDesktopSearchResource.Text
                    Exit Select
                Case FileType.VB
                    searchQuery = WindowsDesktopSearchResource.VB
                    Exit Select
                Case FileType.Xml
                    searchQuery = WindowsDesktopSearchResource.Xml
                    Exit Select
            End Select
            Return searchQuery
        End Function
        ''' <summary>
        '''  Gets result of file serach for specified search criteria.
        ''' </summary>
        ''' <param name="fileResultReader">Object of OleDbDataReader.</param>
        ''' <returns>List of files match specified criteria.</returns>
        Private Shared Function GetFileSearchResult(ByVal fileResultReader As OleDbDataReader) As List(Of FileInfo)
            Dim fileInfo As List(Of FileInfo) = New List(Of FileInfo)()
            While fileResultReader.Read()
                Dim info As FileInfo = New FileInfo()
                'Initialize object of FileInfo class from result of query.
                If Not fileResultReader.GetValue(0) Is Convert.DBNull Then
                    info.Name = fileResultReader.GetString(0)
                End If
                If Not fileResultReader.GetValue(1) Is Convert.DBNull Then
                    info.DateModified = fileResultReader.GetDateTime(1)
                End If
                If Not fileResultReader.GetValue(2) Is Convert.DBNull Then
                    info.Size = CType(fileResultReader.GetInt64(2), UInteger)
                End If
                If Not fileResultReader.GetValue(3) Is Convert.DBNull Then
                    info.SearchLocation = fileResultReader.GetString(3)
                    ' Remove "file" prefix from search location.
                    If info.SearchLocation.StartsWith("file:", StringComparison.InvariantCultureIgnoreCase) Then
                        info.SearchLocation = info.SearchLocation.Substring(5).Trim()
                    Else
                        Continue While
                    End If
                End If
                If Not fileResultReader.GetValue(4) Is Convert.DBNull Then
                    Dim authorList As List(Of String) = New List(Of String)()
                    Dim authors As String() = DirectCast(fileResultReader.GetValue(4), String())
                    For Each author As String In authors
                        authorList.Add(author)
                    Next
                    info.Author = authorList
                End If
                If Not fileResultReader.GetValue(5) Is Convert.DBNull Then
                    info.DateCreated = fileResultReader.GetDateTime(5)
                End If
                If Not fileResultReader.GetValue(6) Is Convert.DBNull Then
                    info.Title = CType(fileResultReader.GetValue(6), String)
                Else
                    info.Title = String.Empty
                End If
                If Not fileResultReader.GetValue(7) Is Convert.DBNull Then
                    Dim attributeValue As Long = fileResultReader.GetInt64(7)
                    'Consider only common attributes of file and neglect other attributes.
                    attributeValue = attributeValue And (Not 128)
                    attributeValue = attributeValue And (Not 64)
                    attributeValue = attributeValue And (Not 8)
                    info.Attributes = CType(attributeValue, FileAttributes)
                End If
                fileInfo.Add(info)
            End While
            Return fileInfo
        End Function
        ''' <summary>
        '''  Gets result of email serach for specified search criteria.
        ''' </summary>
        ''' <param name="emailResultReader">Object of OleDbDataReader.</param>
        ''' <returns>List of emails matched specified criteria.</returns>
        Private Shared Function GetEmailSearchResult(ByVal emailResultReader As OleDbDataReader) As List(Of EmailInfo)
            Dim emailInfoResult As List(Of EmailInfo) = New List(Of EmailInfo)()
            While emailResultReader.Read()
                Dim emailInfo As EmailInfo = New EmailInfo()
                'Initialize object of EmailInfo class from result of query.
                If Not emailResultReader.GetValue(0) Is Convert.DBNull Then
                    emailInfo.Subject = DirectCast(emailResultReader.GetValue(0), String)
                End If
                If Not emailResultReader.GetValue(1) Is Convert.DBNull Then
                    emailInfo.Size = CType(emailResultReader.GetInt64(1), UInteger)
                End If
                If Not emailResultReader.GetValue(2) Is Convert.DBNull Then
                    Dim fromNames As String() = DirectCast(emailResultReader.GetValue(2), String())
                    Dim fromNamesList As String = ""
                    For Each fromName As String In fromNames
                        fromNamesList += fromName + "; "
                    Next
                    emailInfo.From = fromNamesList
                End If
                If Not emailResultReader.GetValue(3) Is Convert.DBNull Then
                    Dim idList As String() = DirectCast(emailResultReader.GetValue(3), String())
                    Dim toList As List(Of String) = New List(Of String)()
                    For Each id As String In idList
                        toList.Add(id)
                    Next
                    emailInfo.ToList = toList
                End If
                If Not emailResultReader.GetValue(4) Is Convert.DBNull Then
                    emailInfo.DateReceived = emailResultReader.GetDateTime(4)
                End If
                If Not emailResultReader.GetValue(5) Is Convert.DBNull Then
                    emailInfo.HasAttachments = emailResultReader.GetBoolean(5)
                End If
                If Not emailResultReader.GetValue(6) Is Convert.DBNull Then
                    Dim attachments As String() = DirectCast(emailResultReader.GetValue(6), String())
                    'String attachment = "";
                    Dim attachmentList As List(Of String) = New List(Of String)()
                    For Each attachment As String In attachments
                        attachmentList.Add(attachment)
                    Next
                    emailInfo.Attachments = attachmentList
                End If
                If Not emailResultReader.GetValue(7) Is Convert.DBNull Then
                    Dim priorityLevel As Int32 = emailResultReader.GetInt32(7)
                    emailInfo.Priority = CType(priorityLevel, EmailPriority)
                Else
                    emailInfo.Priority = EmailPriority.Normal
                End If
                emailInfoResult.Add(emailInfo)
            End While
            Return emailInfoResult
        End Function
        ''' <summary>
        '''  Gets result of picture serach for specified search criteria.
        ''' </summary>
        ''' <param name="pictureResultReader">Object of OleDbDataReader.</param>
        ''' <returns>List of picture files matched specified criteria.</returns>
        Private Shared Function GetPictureSearchResult(ByVal pictureResultReader As OleDbDataReader) As List(Of PictureInfo)
            Dim pictureInfoResult As List(Of PictureInfo) = New List(Of PictureInfo)()
            While pictureResultReader.Read()
                ' Initialize object of PictureInfo class from result of query. 
                Dim pictureInfo As PictureInfo = New PictureInfo()
                If Not pictureResultReader.GetValue(0) Is Convert.DBNull Then
                    pictureInfo.Name = pictureResultReader.GetString(0)
                End If
                If Not pictureResultReader.GetValue(1) Is Convert.DBNull Then
                    pictureInfo.Size = CType(pictureResultReader.GetInt64(1), UInteger)
                End If
                If Not pictureResultReader.GetValue(2) Is Convert.DBNull Then
                    pictureInfo.SearchLocation = pictureResultReader.GetString(2)
                End If
                If Not pictureResultReader.GetValue(3) Is Convert.DBNull Then
                    Dim taglist As List(Of String) = New List(Of String)()
                    Dim picturTags As String() = DirectCast(pictureResultReader.GetValue(3), String())
                    For Each pictureTag As String In picturTags
                        taglist.Add(pictureTag)
                    Next
                    pictureInfo.Tags = taglist
                End If
                If Not pictureResultReader.GetValue(4) Is Convert.DBNull Then
                    Dim ratingStarCount As UInteger = CType(pictureResultReader.GetInt32(4), UInteger)
                    Select Case ratingStarCount
                        Case 1
                            pictureInfo.Rating = 1
                            Exit Select
                        Case 25
                            pictureInfo.Rating = 2
                            Exit Select
                        Case 50
                            pictureInfo.Rating = 3
                            Exit Select
                        Case 75
                            pictureInfo.Rating = 4
                            Exit Select
                        Case 99
                            pictureInfo.Rating = 5
                            Exit Select
                    End Select
                End If
                If Not pictureResultReader.GetValue(5) Is Convert.DBNull Then
                    Dim test As Object = pictureResultReader.GetValue(5)
                    pictureInfo.DateTaken = Convert.ToDateTime(test)
                End If
                If Not pictureResultReader.GetValue(6) Is Convert.DBNull Then
                    Dim attributeValue As Long = pictureResultReader.GetInt64(6)
                    'Consider only common attributes of file and neglect other attributes.
                    attributeValue = attributeValue And (Not 128)
                    attributeValue = attributeValue And (Not 64)
                    attributeValue = attributeValue And (Not 8)
                    pictureInfo.Attributes = CType(attributeValue, FileAttributes)
                End If
                pictureInfoResult.Add(pictureInfo)
            End While
            Return pictureInfoResult
        End Function
        ''' <summary>
        '''  Gets result of music serach for specified search criteria.
        ''' </summary>
        ''' <param name="musicResultReader">Object of OleDbDataReader.</param>
        ''' <returns>List of music files matched specified criteria.</returns>
        Private Shared Function GetMusicSearchResult(ByVal musicResultReader As OleDbDataReader) As List(Of MusicInfo)
            Dim musicInfoResult As List(Of MusicInfo) = New List(Of MusicInfo)()
            While musicResultReader.Read()
                Dim musicInfo As MusicInfo = New MusicInfo()
                'Initialize object of MusicInfo class with result of query.
                If Not musicResultReader.GetValue(0) Is Convert.DBNull Then
                    musicInfo.Name = musicResultReader.GetString(0)
                End If
                If Not musicResultReader.GetValue(1) Is Convert.DBNull Then
                    musicInfo.Size = CType(musicResultReader.GetInt64(1), UInteger)
                End If
                If Not musicResultReader.GetValue(2) Is Convert.DBNull Then
                    musicInfo.SearchLocation = musicResultReader.GetString(2)
                End If
                If Not musicResultReader.GetValue(3) Is Convert.DBNull Then
                    Dim ratingStarCount As UInteger = CType(musicResultReader.GetInt32(3), UInteger)
                    Select Case ratingStarCount
                        Case 1
                            musicInfo.Rating = 1
                            Exit Select
                        Case 25
                            musicInfo.Rating = 2
                            Exit Select
                        Case 50
                            musicInfo.Rating = 3
                            Exit Select
                        Case 75
                            musicInfo.Rating = 4
                            Exit Select
                        Case 99
                            musicInfo.Rating = 5
                            Exit Select
                    End Select
                End If
                If Not musicResultReader.GetValue(4) Is Convert.DBNull Then
                    musicInfo.Album = musicResultReader.GetString(4)
                End If
                If Not musicResultReader.GetValue(5) Is Convert.DBNull Then
                    Dim artistList As List(Of String) = New List(Of String)()
                    Dim artists As String() = DirectCast(musicResultReader.GetValue(5), String())
                    For Each artist As String In artists
                        artistList.Add(artist)
                    Next
                    musicInfo.Artists = artistList
                End If
                If Not musicResultReader.GetValue(6) Is Convert.DBNull Then
                    Dim attributeValue As Long = musicResultReader.GetInt64(6)
                    attributeValue = attributeValue And (Not 128)
                    attributeValue = attributeValue And (Not 64)
                    attributeValue = attributeValue And (Not 8)
                    musicInfo.Attributes = CType(attributeValue, FileAttributes)
                End If
                musicInfoResult.Add(musicInfo)
            End While
            Return musicInfoResult
        End Function
#End Region

#Region "Public Methods"
        ''' <summary>
        ''' This method search files by specified criteria in local catalog.
        ''' </summary>
        ''' <param name="fileSearchCriteria">Specifies file search criteria.</param>
        ''' <returns>Returns list of files based on the specified search criteria.</returns>
        ''' <exception cref="ArgumentNullException">The required parameter is null or empty.</exception>
        ''' <exception cref="ArgumentException">The specified parameter is not valid.</exception>
        ''' <exception cref="DesktopSearchException"> Call to API has raised error.</exception>
        Public Function Search(ByVal fileSearchCriteria As FileSearchCriteria) As List(Of FileInfo)
            If fileSearchCriteria Is Nothing Then
                Throw New ArgumentNullException("fileSearchCriteria")
            End If
            Dim fileInfoResult As List(Of FileInfo) = New List(Of FileInfo)()
            Dim searchQuery As String = String.Empty
            searchQuery += GetFileTypeQuery(fileSearchCriteria)
            ' Get name of file to be searched if specified and create a query that will 
            ' be used to generate sql query. 
            If Not [String].IsNullOrEmpty(fileSearchCriteria.FileName) Then
                searchQuery += WindowsDesktopSearchResource.FileName + fileSearchCriteria.FileName + " "
            End If
            ' Check the value for date filter and date compare option.
            ' If appropriate value is not provided then do not include date in to filter result of search.
            Dim currentDateFilter As String = fileSearchCriteria.FileDateFilter.ToString().ToLower()
            If Not fileSearchCriteria.FileDateFilter = FileDateFilter.None Then
                If Not fileSearchCriteria.DateCompareOption = DateCompareOption.Any Then
                    Select Case fileSearchCriteria.DateCompareOption
                        Case DateCompareOption.After
                            searchQuery += currentDateFilter + ":>" + fileSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.Before
                            searchQuery += currentDateFilter + ":<" + fileSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.[Is]
                            searchQuery += currentDateFilter + ":=" + fileSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                    End Select
                End If
            End If
            ' Get the authors of file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(fileSearchCriteria.FileAuthor) Then
                searchQuery += WindowsDesktopSearchResource.Author + "(" + fileSearchCriteria.FileAuthor + ")"
            End If
            ' Get the tags of file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(fileSearchCriteria.FileTag) Then
                searchQuery += WindowsDesktopSearchResource.FileTag + " " + fileSearchCriteria.FileTag + " "
            End If
            ' Get the extension of file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(fileSearchCriteria.Extension) Then
                searchQuery += WindowsDesktopSearchResource.Extension + fileSearchCriteria.Extension + " "
            End If
            ' Get the location where file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(fileSearchCriteria.SearchLocation) Then
                'append "\" at the end to exclude specified location from search result.
                '"(" and ")" used for handling long string of location to be searched.
                If fileSearchCriteria.SearchLocation.EndsWith("\") Then
                    fileSearchCriteria.SearchLocation = fileSearchCriteria.SearchLocation.TrimEnd("\"c)
                End If
                searchQuery += WindowsDesktopSearchResource.Path + "(" + fileSearchCriteria.SearchLocation + "\" + ")" + " "
            End If
            ' Get the size and compare it with specified size comaparsion options and 
            ' create a query that will be used to generate sql query. 
            If Not fileSearchCriteria.SizeCompareOption = SizeCompareOption.Any Then
                Select Case fileSearchCriteria.SizeCompareOption
                    Case SizeCompareOption.Equals
                        searchQuery += CType(WindowsDesktopSearchResource.EqualSize, String) + CType(fileSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsGreaterThan
                        searchQuery += CType(WindowsDesktopSearchResource.GreaterThanSize, String) + CType(fileSearchCriteria.Size, String) + "kb"
                        Exit Select
                    Case SizeCompareOption.IsLessThan
                        searchQuery += CType(WindowsDesktopSearchResource.LessThanSize, String) + CType(fileSearchCriteria.Size, String) + " kb "
                        Exit Select
                End Select
            End If
            ' Check any criteria for searching is specified or not.
            If [String].IsNullOrEmpty(searchQuery) Then
                Throw New ArgumentException("Specified search criteria is not sufficient.")
            End If
            Dim queryHelper As CSearchQueryHelper = InitializeSearch()
            ' Name of columns returned by query in result.
            queryHelper.QuerySelectColumns = WindowsDesktopSearchResource.FileSearchQueryColumns
            Dim query As String = String.Empty
            Try
                ' Generate sql query according to criteria specified.
                query = queryHelper.GenerateSQLFromUserQuery(searchQuery)
                ' Fire generated query against system database.
                Dim reader As OleDbDataReader = GetQueryResponse(query)
                ' Get fils matched specified criteria.
                fileInfoResult = GetFileSearchResult(reader)
            Catch exception As Exception
                Throw New DesktopSearchException(exception.Message, exception)
            Finally
                systemDbconnection.Close()
            End Try
            Return fileInfoResult
        End Function
        ''' <summary>
        ''' This method search emails by specified criteria in local catalog.
        ''' </summary>
        ''' <param name="emailSearchCriteria">Specifies file search criteria.</param>
        ''' <returns>Returns list of emails based on the specified search criteria.
        '''  If criteria is not specified then all emails will be searched.
        '''  </returns>
        ''' <exception cref="ArgumentException">The specified parameter is not valid.</exception>
        ''' <exception cref="DesktopSearchException"> Call to API has raised error.</exception>
        Public Function Search(ByVal emailSearchCriteria As EmailSearchCriteria) As List(Of EmailInfo)
            If emailSearchCriteria Is Nothing Then
                Throw New ArgumentNullException("emailSearchCriteria")
            End If
            Dim emailInfo As List(Of EmailInfo) = New List(Of EmailInfo)()
            Dim searchQuery As String = String.Empty
            searchQuery += WindowsDesktopSearchResource.Emails + " "
            ' Get the email address of recevier of the email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.EmailTo) Then
                searchQuery += WindowsDesktopSearchResource.Receiver + emailSearchCriteria.EmailTo + " "
            End If
            ' Get the email address of sender of email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.EmailFrom) Then
                searchQuery += WindowsDesktopSearchResource.Sender + emailSearchCriteria.EmailFrom + " "
            End If
            ' Get the location where file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.SearchLocation) Then
                searchQuery += WindowsDesktopSearchResource.Path + emailSearchCriteria.SearchLocation + " "
            End If
            ' Get the size and compare it with specified size comparision options and 
            ' create a query that will be used to generate sql query. 
            If Not emailSearchCriteria.SizeCompareOption = SizeCompareOption.Any Then
                Select Case emailSearchCriteria.SizeCompareOption
                    Case SizeCompareOption.Equals
                        searchQuery += CType(WindowsDesktopSearchResource.EqualSize, String) + CType(emailSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsGreaterThan
                        searchQuery += CType(WindowsDesktopSearchResource.GreaterThanSize, String) + CType(emailSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsLessThan
                        searchQuery += CType(WindowsDesktopSearchResource.LessThanSize, String) + CType(emailSearchCriteria.Size, String) + " kb "
                        Exit Select
                End Select
            End If
            ' Check the value for date filter and date compare option.
            ' If appropriate value is not provided then do not include date in to filter result of search.
            Dim currentDateFilter As String = emailSearchCriteria.EmailDateFilter.ToString().ToLower()
            If Not emailSearchCriteria.EmailDateFilter = EmailDateFilter.None Then
                If Not emailSearchCriteria.DateCompareOption = DateCompareOption.Any Then
                    Select Case emailSearchCriteria.DateCompareOption
                        Case DateCompareOption.After
                            searchQuery += currentDateFilter + ":>" + emailSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.Before
                            searchQuery += currentDateFilter + ":<" + emailSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.[Is]
                            searchQuery += currentDateFilter + ":=" + emailSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                    End Select
                End If
            End If
            ' Get the extension of email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.Extension) Then
                searchQuery += WindowsDesktopSearchResource.Extension + emailSearchCriteria.Extension + " "
            End If
            ' Get the subject of email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.EmailSubject) Then
                searchQuery += WindowsDesktopSearchResource.EmailSubject + emailSearchCriteria.EmailSubject + " "
            End If
            ' Get the attachments of email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(emailSearchCriteria.EmailAttachments) Then
                searchQuery += WindowsDesktopSearchResource.Attachments + "(" + emailSearchCriteria.EmailAttachments + ")"
            End If
            ' Get the priority level associated with email to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not emailSearchCriteria.Priority = EmailPriority.None Then
                searchQuery += CType(WindowsDesktopSearchResource.Priority, String) + CType(emailSearchCriteria.Priority, String)
            End If
            Dim queryHelper As CSearchQueryHelper = InitializeSearch()
            ' Name of columns returned by query in result.
            queryHelper.QuerySelectColumns = WindowsDesktopSearchResource.EmailSearchQueryColumns
            Dim query As String = String.Empty
            Try
                ' Generate sql query according to criteria specified.
                query = queryHelper.GenerateSQLFromUserQuery(searchQuery)
                ' Fire generated query aganist local catalog.
                Dim reader As OleDbDataReader = GetQueryResponse(query)
                ' Get email fils matched specified criteria.
                emailInfo = GetEmailSearchResult(reader)
            Catch exception As Exception
                Throw New DesktopSearchException(exception.Message, exception)
            Finally
                systemDbconnection.Close()
            End Try
            Return emailInfo
        End Function
        ''' <summary>
        ''' This method search pictures by specified criteria in local catalog.
        ''' </summary>
        ''' <param name="pictureSearchCriteria">Specifies file search criteria.</param>
        ''' <returns>Returns list of picture based on the specified search criteria.
        ''' If seach criteria is not specified then all picture files will be searched.
        '''</returns>
        ''' <exception cref="ArgumentException">The specified parameter is not valid.</exception>
        ''' <exception cref="DesktopSearchException"> Call to API has raised error.</exception>
        Public Function Search(ByVal pictureSearchCriteria As PictureSearchCriteria) As List(Of PictureInfo)
            If pictureSearchCriteria Is Nothing Then
                Throw New ArgumentNullException()
            End If
            Dim pictureInfo As List(Of PictureInfo) = New List(Of PictureInfo)()
            Dim searchQuery As String = String.Empty
            searchQuery += WindowsDesktopSearchResource.PictureFile + " "
            ' Get the extension of picture to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(pictureSearchCriteria.Extension) Then
                searchQuery += WindowsDesktopSearchResource.Extension + pictureSearchCriteria.Extension + " "
            End If
            ' Get the name of picture to be searched if it is specfied and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(pictureSearchCriteria.PictureName) Then
                searchQuery += WindowsDesktopSearchResource.PictureName + pictureSearchCriteria.PictureName + " "
            End If
            ' Get the tag of picture to be searched if it is specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(pictureSearchCriteria.PictureTag) Then
                searchQuery += WindowsDesktopSearchResource.PictureTag + pictureSearchCriteria.PictureTag + " "
            End If
            ' Check the value for date filter and date compare option. 
            ' If appropriate value is not provided then do not include date in to filter result of search.
            Dim currentDateFilter As String = pictureSearchCriteria.PictureDateFilter.ToString().ToLower()
            If Not pictureSearchCriteria.PictureDateFilter = PictureDateFilter.None Then
                If Not pictureSearchCriteria.DateCompareOption = DateCompareOption.Any Then
                    Select Case pictureSearchCriteria.DateCompareOption
                        Case DateCompareOption.After
                            searchQuery += currentDateFilter + ":>" + pictureSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.Before
                            searchQuery += currentDateFilter + ":<" + pictureSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.[Is]
                            searchQuery += currentDateFilter + ":=" + pictureSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                    End Select
                End If
            End If
            ' Get the size and compare it with specified size comaparsion options and 
            ' create a query that will be used to generate sql query. 
            If Not pictureSearchCriteria.SizeCompareOption = SizeCompareOption.Any Then
                Select Case pictureSearchCriteria.SizeCompareOption
                    Case SizeCompareOption.Equals
                        searchQuery += CType(WindowsDesktopSearchResource.EqualSize, String) + CType(pictureSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsGreaterThan
                        searchQuery += CType(WindowsDesktopSearchResource.GreaterThanSize, String) + CType(pictureSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsLessThan
                        searchQuery += CType(WindowsDesktopSearchResource.LessThanSize, String) + CType(pictureSearchCriteria.Size, String) + " kb "
                        Exit Select
                End Select
            End If
            ' Get the title of picture to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(pictureSearchCriteria.PictureTitle) Then
                searchQuery += WindowsDesktopSearchResource.PictureTitle + pictureSearchCriteria.PictureTitle + " "
            End If
            ' Get the location where file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(pictureSearchCriteria.SearchLocation) Then
                'append "\" at the end to exclude specified location from search result.
                '"(" and ")" used for handling long string of location to be searched.
                If pictureSearchCriteria.SearchLocation.EndsWith("\") Then
                    pictureSearchCriteria.SearchLocation = pictureSearchCriteria.SearchLocation.TrimEnd("\"c)
                End If
                searchQuery += WindowsDesktopSearchResource.Path + "(" + pictureSearchCriteria.SearchLocation + "\" + ")" + " "
            End If
            Dim queryHelper As CSearchQueryHelper = InitializeSearch()
            ' Name of columns returned by query in result.
            queryHelper.QuerySelectColumns = WindowsDesktopSearchResource.PictureSearchQueryColumns
            Dim query As String = String.Empty
            Try
                ' Generate sql query according to criteria specified.
                query = queryHelper.GenerateSQLFromUserQuery(searchQuery)
                ' Fire generated query that specified search criteria for searchng
                ' against local catalog.
                Dim reader As OleDbDataReader = GetQueryResponse(query)
                ' Get picture files matched specified criteria.
                pictureInfo = GetPictureSearchResult(reader)
            Catch exception As Exception
                Throw New DesktopSearchException(exception.Message, exception)
            Finally
                systemDbconnection.Close()
            End Try
            Return pictureInfo
        End Function
        ''' <summary> 
        ''' This method search music files by specified criteria in local catalog.
        ''' </summary>
        ''' <param name="musicSearchCriteria">Specifies file search criteria.</param>
        ''' <returns>Returns list of music based on the specified search criteria.
        '''If criteria is not specified all music files to be searched.
        '''</returns>
        ''' <exception cref="ArgumentException">The specified parameter is not valid.</exception>
        ''' <exception cref="DesktopSearchException"> Call to API has raised error.</exception>
        Public Function Search(ByVal musicSearchCriteria As MusicSearchCriteria) As List(Of MusicInfo)
            If musicSearchCriteria Is Nothing Then
                Throw New ArgumentNullException("musicSearchCriteria")
            End If
            Dim musicInfo As List(Of MusicInfo) = New List(Of MusicInfo)()
            Dim searchQuery As String = String.Empty
            searchQuery += WindowsDesktopSearchResource.MusicFile + " "
            ' Get the size and compare it with specified size comaparsion options and 
            ' create a query that will be used to generate sql query. 
            If Not musicSearchCriteria.SizeCompareOption = SizeCompareOption.Any Then
                Select Case musicSearchCriteria.SizeCompareOption
                    Case SizeCompareOption.Equals
                        searchQuery += CType(WindowsDesktopSearchResource.EqualSize, String) + CType(musicSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsGreaterThan
                        searchQuery += CType(WindowsDesktopSearchResource.GreaterThanSize, String) + CType(musicSearchCriteria.Size, String) + " kb "
                        Exit Select
                    Case SizeCompareOption.IsLessThan
                        searchQuery += CType(WindowsDesktopSearchResource.LessThanSize, String) + CType(musicSearchCriteria.Size, String) + " kb "
                        Exit Select
                End Select
            End If
            ' Get the location where file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(musicSearchCriteria.SearchLocation) Then
                'append "\" at the end to exclude specified location from search result.
                '"(" and ")" used for handling long string of location to be searched.
                If musicSearchCriteria.SearchLocation.EndsWith("\") Then
                    musicSearchCriteria.SearchLocation = musicSearchCriteria.SearchLocation.TrimEnd("\"c)
                End If
                searchQuery += WindowsDesktopSearchResource.Path + "(" + musicSearchCriteria.SearchLocation + "\" + ")" + " "
            End If
            ' Get the name of music file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(musicSearchCriteria.MusicTitle) Then
                searchQuery += WindowsDesktopSearchResource.MusicTitle + musicSearchCriteria.MusicTitle + " "
            End If
            ' Check the value for date filter and date compare option.
            ' If appropriate value is not provided then do not include date in to filter result of search.
            Dim currentDateFilter As String = musicSearchCriteria.MusicDateFilter.ToString().ToLower()
            If Not musicSearchCriteria.MusicDateFilter = MusicDateFilter.None Then
                If Not musicSearchCriteria.DateCompareOption = DateCompareOption.Any Then
                    Select Case musicSearchCriteria.DateCompareOption
                        Case DateCompareOption.After
                            searchQuery += currentDateFilter + ":>" + musicSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.Before
                            searchQuery += currentDateFilter + ":<" + musicSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                        Case DateCompareOption.[Is]
                            searchQuery += currentDateFilter + ":=" + musicSearchCriteria.[Date].ToShortDateString() + " "
                            Exit Select
                    End Select
                End If
            End If
            ' Get the artists of music file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(musicSearchCriteria.ArtistName) Then
                searchQuery += WindowsDesktopSearchResource.MusicArtists + musicSearchCriteria.ArtistName + " "
            End If
            ' Get the album name of the music file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(musicSearchCriteria.AlbumName) Then
                searchQuery += WindowsDesktopSearchResource.MusicAlbum + musicSearchCriteria.AlbumName + " "
            End If
            ' Get the extesion of music file to be searched if it specified and 
            ' create a query that will be used to generate sql query. 
            If Not [String].IsNullOrEmpty(musicSearchCriteria.Extension) Then
                searchQuery += WindowsDesktopSearchResource.Extension + musicSearchCriteria.Extension + " "
            End If
            Dim queryHelper As CSearchQueryHelper = InitializeSearch()
            ' Name of columns returned by query in result.
            queryHelper.QuerySelectColumns = WindowsDesktopSearchResource.MusicSearchQueryColumns
            Dim query As String = String.Empty
            Try
                ' Generate sql query according to criteria specified.
                query = queryHelper.GenerateSQLFromUserQuery(searchQuery)
                ' Fire generated query aganist local catalog.
                Dim reader As OleDbDataReader = GetQueryResponse(query)
                ' Get music fils matched specified criteria.
                musicInfo = GetMusicSearchResult(reader)
            Catch exception As Exception
                Throw New DesktopSearchException(exception.Message, exception)
            Finally
                systemDbconnection.Close()
            End Try
            Return musicInfo
        End Function
        ''' <summary>
        ''' This method search specified file in local catalog.
        ''' </summary>
        ''' <param name="fileName">Specifies file name.</param>
        ''' <returns>Returns list of files based on specfied file name.</returns>
        ''' <exception cref="ArgumentNullException">The required parameter is null or empty.</exception>
        ''' <exception cref="DesktopSearchException"> Call to API has raised error.</exception>
        Public Function Search(ByVal fileName As String) As List(Of FileInfo)
            If [String].IsNullOrEmpty(fileName) Then
                Throw New ArgumentNullException(WindowsDesktopSearchResource.FileNullMessage)
            End If
            Dim fileInfoResult As List(Of FileInfo) = New List(Of FileInfo)()
            Dim searchQuery As String = String.Empty
            ' Get name of file to be searched if specified and create a query that will 
            ' be used to generate sql query. 
            searchQuery += WindowsDesktopSearchResource.FileName + fileName
            Dim queryHelper As CSearchQueryHelper = InitializeSearch()
            ' Name of columns returned by query in result.
            queryHelper.QuerySelectColumns = WindowsDesktopSearchResource.FileSearchQueryColumns
            Dim query As String = String.Empty
            Try
                ' Generate sql query according to criteria specified.
                query = queryHelper.GenerateSQLFromUserQuery(searchQuery)
                ' Fire generated query against system database.
                Dim reader As OleDbDataReader = GetQueryResponse(query)
                ' Get files matched specified criteria.
                fileInfoResult = GetFileSearchResult(reader)
            Catch exception As Exception
                Throw New DesktopSearchException(exception.Message, exception)
            Finally
                systemDbconnection.Close()
            End Try
            Return fileInfoResult
        End Function
#End Region

    End Class
#End Region

#Region "Public Classes"
    ''' <summary>
    ''' Represents common search criteria for all items.
    ''' </summary>
    Public Class SearchCriteria

#Region "Private Members"
        ''' <summary>
        ''' Specifies size of item to be searched.
        ''' </summary>
        Private m_size As UInteger
        ''' <summary>
        ''' Specifies date associated with the items to be searched.  
        ''' </summary>
        Private m_date As DateTime
        ''' <summary>
        ''' Specifies value of date comparison options.
        ''' </summary>
        Private m_dateCompareOption As DateCompareOption
        ''' <summary>
        ''' Specifies value of size comparison options.
        ''' </summary>
        Private m_sizeCompareOption As SizeCompareOption
        ''' <summary>
        ''' Specifies location where file to be searched.
        ''' </summary>
        Private m_searchLocation As String
        ''' <summary>
        ''' Extension of item.
        ''' </summary>
        Private fileExtension As String
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Size of the items in Kb. 
        ''' Size is not itself sufficent criteria for searching. 
        ''' Default size is 0 kb.
        ''' </summary>
        Public Property Size() As UInteger
            Get
                Return m_size
            End Get
            Set(ByVal value As UInteger)
                m_size = value
            End Set
        End Property
        ''' <summary>
        ''' Represents date associated with the items to be searched. 
        '''  If date is not specified then searching is performed by current date. 
        ''' </summary>
        Public Property [Date]() As DateTime
            Get
                Return m_date
            End Get
            Set(ByVal value As DateTime)
                m_date = value
            End Set
        End Property
        ''' <summary>
        ''' Represents different date comparison options.
        ''' Possible values are represented by DateCompareOption enumeration.
        '''  Search is not performed according to date if value for this property is set as “None”.
        ''' </summary>
        Public Property DateCompareOption() As DateCompareOption
            Get
                Return m_dateCompareOption
            End Get
            Set(ByVal value As DateCompareOption)
                m_dateCompareOption = value
            End Set
        End Property
        ''' <summary>
        ''' Represents different size comparison options.
        '''  Possible values are represented by SizeCompareOption enumeration. 
        ''' Searching is not performed according to size if value for SizeCompareOption enumeration is “Any”.
        ''' </summary>
        Public Property SizeCompareOption() As SizeCompareOption
            Get
                Return m_sizeCompareOption
            End Get
            Set(ByVal value As SizeCompareOption)
                m_sizeCompareOption = value
            End Set
        End Property
        ''' <summary>
        ''' Represents location to be searched for items. 
        ''' Location for emails is standard subfolder like Inbox, outboxes and sent items etc. of “mail folder”.
        ''' </summary>
        Public Property SearchLocation() As String
            Get
                Return m_searchLocation
            End Get
            Set(ByVal value As String)
                m_searchLocation = value
            End Set
        End Property
        ''' <summary>
        ''' Represents extension of items to be searched.
        ''' </summary>
        Public Property Extension() As String
            Get
                Return fileExtension
            End Get
            Set(ByVal value As String)
                fileExtension = value
            End Set
        End Property
#End Region
        ''' <summary>
        ''' Initializes search criteria for file search.
        ''' </summary>
        Public Sub New()
            Me.[Date] = DateTime.Now
        End Sub
    End Class
    ''' <summary>
    ''' This class contains properties related to all files. 
    ''' This is used to specify file search criteria. 
    ''' If value for any of the search criteria is not specified then file is not searched by that parameter.
    ''' </summary>
    Public Class FileSearchCriteria
        Inherits SearchCriteria
#Region "Private Members"
        ''' <summary>
        ''' Specifies author of file.
        ''' </summary>
        Private m_fileAuthor As String
        ''' <summary>
        ''' Specifies name of file to be searched.
        ''' </summary>
        Private m_fileName As String
        ''' <summary>
        ''' Specifies tag of file.
        ''' </summary>
        Private m_fileTag As String
        ''' <summary>
        ''' Specifies type of file to be searched.
        ''' </summary>
        Private m_fileType As FileType
        ''' <summary>
        ''' Specifies date filters associated with file.
        ''' </summary>
        Private m_fileDateFilter As FileDateFilter
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Name of file to be searched.
        ''' </summary>
        Public Property FileName() As String
            Get
                Return m_fileName
            End Get
            Set(ByVal value As String)
                m_fileName = value
            End Set
        End Property
        ''' <summary>
        ''' List of tags associated with file.
        ''' </summary>
        Public Property FileTag() As String
            Get
                Return m_fileTag
            End Get
            Set(ByVal value As String)
                m_fileTag = value
            End Set
        End Property
        ''' <summary>
        ''' Author of file.
        ''' </summary>
        Public Property FileAuthor() As String
            Get
                Return m_fileAuthor
            End Get
            Set(ByVal value As String)
                m_fileAuthor = value
            End Set
        End Property
        ''' <summary>
        ''' Type of file to be searched. 
        ''' If this property set as “All”, user must set at least one other property which is sufficient for search.
        ''' </summary>
        Public Property FileType() As FileType
            Get
                Return m_fileType
            End Get
            Set(ByVal value As FileType)
                m_fileType = value
            End Set
        End Property
        ''' <summary>
        ''' Date filters associated with file. 
        ''' Possible date filters are represented by FileDateFilter enumeration.
        '''  Searching is not performed according to date if value for FileDateFilter enumeration is “None”.
        '''  Default value is “None”.
        ''' </summary>
        Public Property FileDateFilter() As FileDateFilter
            Get
                Return m_fileDateFilter
            End Get
            Set(ByVal value As FileDateFilter)
                m_fileDateFilter = value
            End Set
        End Property
#End Region

#Region "Constructors"
        ''' <summary>
        ''' Initializes search criteria for file search.
        ''' </summary>
        Public Sub New(ByVal searchCriteria As SearchCriteria, ByVal fileAuthor As String, _
                       ByVal fileName As String, ByVal fileTag As String, _
                       ByVal fileType As FileType, ByVal fileDateFilter As FileDateFilter)
            Me.FileAuthor = fileAuthor
            Me.FileName = fileName
            Me.FileTag = fileTag
            Me.FileType = fileType
            Me.FileDateFilter = fileDateFilter
            If searchCriteria IsNot Nothing Then
                Me.[Date] = searchCriteria.[Date]
                Me.DateCompareOption = searchCriteria.DateCompareOption
                Me.Extension = searchCriteria.Extension
                Me.Size = searchCriteria.Size
                Me.SearchLocation = searchCriteria.SearchLocation
                Me.SizeCompareOption = searchCriteria.SizeCompareOption
            Else
                Me.[Date] = DateTime.Now
            End If
        End Sub
        ''' <summary>
        '''  Initializes default search criteria for all files. 
        ''' </summary>
        Public Sub New()
            Me.[Date] = DateTime.Now
        End Sub
#End Region

    End Class
    ''' <summary>
    ''' This class contains properties related to emails. 
    ''' This is used to specify email search criteria. 
    ''' If value for any of the search criteria is not specified then email is not searched by that parameter. 
    ''' Email programs supported are microsoft office outlook 2003 and 2007 ,and windows mail. 
    ''' If serching is performed inside subfolder of “mail folder” then emails displayed from all supported email programs that contain specified subfolder.
    '''</summary>
    Public Class EmailSearchCriteria
        Inherits SearchCriteria
#Region "Private Members"
        ''' <summary>
        ''' Specifies subject of email to be searched.
        ''' </summary>
        Private m_emailSubject As String
        ''' <summary>
        ''' Specifies sender of email to be searched.
        ''' </summary>
        Private m_emailFrom As String
        ''' <summary>
        ''' Specifies receiver of email to be searched.
        ''' </summary>
        Private m_emailTo As String
        ' private List<string> emailTo;
        ''' <summary>
        ''' Specifies date filters associated with email.
        ''' </summary>
        Private m_emailDateFilter As EmailDateFilter
        ''' <summary>
        ''' Specifies list of attachments associated with email.
        ''' </summary>
        Private m_emailAttachments As String
        ''' <summary>
        ''' Specifies priority associated with email.
        ''' </summary>
        Private m_priority As EmailPriority
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Represents the string to be searched in the subject field of an email.
        ''' </summary>
        Public Property EmailSubject() As String
            Get
                Return m_emailSubject
            End Get
            Set(ByVal value As String)
                m_emailSubject = value
            End Set
        End Property
        ''' <summary>
        ''' Id of the email sender.
        ''' </summary>
        Public Property EmailFrom() As String
            Get
                Return m_emailFrom
            End Get
            Set(ByVal value As String)
                m_emailFrom = value
            End Set
        End Property
        ''' <summary>
        ''' Id to be searched in ‘To’ list of the email. 
        ''' </summary>
        Public Property EmailTo() As String
            ' public  List<string> EmailTo
            Get
                Return m_emailTo
            End Get
            Set(ByVal value As String)
                m_emailTo = value
            End Set
        End Property
        ''' <summary>
        ''' Date filters associated with emails. 
        ''' Possible email date filters are represented by EmailDateFilter enumeration. 
        ''' Searching is not performed according to date if value for EmailDateFilter enumeration is “None”. 
        ''' Default value is “None”.
        ''' </summary>
        Public Property EmailDateFilter() As EmailDateFilter
            Get
                Return m_emailDateFilter
            End Get
            Set(ByVal value As EmailDateFilter)
                m_emailDateFilter = value
            End Set
        End Property
        ''' <summary>
        ''' List of attachments associated with email.
        ''' </summary>
        Public Property EmailAttachments() As String
            Get
                Return m_emailAttachments
            End Get
            Set(ByVal value As String)
                m_emailAttachments = value
            End Set
        End Property
        ''' <summary>
        ''' Represents priority associated with email.
        ''' </summary>
        Public Property Priority() As EmailPriority
            Get
                Return m_priority
            End Get
            Set(ByVal value As EmailPriority)
                m_priority = value
            End Set
        End Property
#End Region

#Region "Constructors"
        ''' <summary>
        '''  Initializes search criteria for email search. 
        ''' </summary>
        Public Sub New(ByVal searchCriteria As SearchCriteria, ByVal emailFrom As String, _
                       ByVal emailSubject As String, ByVal emailTo As String, _
                       ByVal emailDateFilter As EmailDateFilter, ByVal emailAttachments As String, _
                       ByVal priority As EmailPriority)
            Me.EmailTo = emailTo
            Me.EmailFrom = emailFrom
            Me.EmailSubject = emailSubject
            Me.EmailDateFilter = emailDateFilter
            Me.Priority = priority
            Me.EmailAttachments = emailAttachments
            If searchCriteria IsNot Nothing Then
                Me.[Date] = searchCriteria.[Date]
                Me.DateCompareOption = searchCriteria.DateCompareOption
                Me.Extension = searchCriteria.Extension
                Me.Size = searchCriteria.Size
                Me.SearchLocation = searchCriteria.SearchLocation
                Me.SizeCompareOption = searchCriteria.SizeCompareOption
            Else
                Me.[Date] = DateTime.Now
            End If
        End Sub
        ''' <summary>
        '''  Initializes default search criteria for emails search. 
        ''' </summary>
        Public Sub New()
            Me.[Date] = DateTime.Now
        End Sub
#End Region
    End Class
    ''' <summary>
    ''' This class contains properties related to pictures. 
    ''' This is used to specify picture search criteria.
    '''  If value for any of the search criteria is not specified then picture file is not searched by that parameter. 
    ''' Jpg, jpeg, eco, bmp, gif, emf, png, psd, wmf, tiff, xpm, pcx, dib, ai, eps are standared type supported by desktop search api.
    ''' </summary>
    Public Class PictureSearchCriteria
        Inherits SearchCriteria
#Region "Private Members"
        ''' <summary>
        ''' Specifies name of picture file.
        ''' </summary>
        Private m_pictureName As String
        ''' <summary>
        ''' Specifies tag of picture file.
        ''' </summary>
        Private m_pictureTag As String
        ''' <summary>
        ''' Specifies title of picture file.
        ''' </summary>
        Private m_pictureTitle As String
        ''' <summary>
        ''' Specifies date filters associated with picture file.
        ''' </summary>
        Private m_pictureDateFilter As PictureDateFilter
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Name of picture file.
        ''' </summary>
        Public Property PictureName() As String
            Get
                Return m_pictureName
            End Get
            Set(ByVal value As String)
                m_pictureName = value
            End Set
        End Property
        ''' <summary>
        ''' Tag of picture file.
        ''' </summary>
        Public Property PictureTag() As String
            Get
                Return m_pictureTag
            End Get
            Set(ByVal value As String)
                m_pictureTag = value
            End Set
        End Property
        ''' <summary>
        ''' Title of picture file.
        ''' </summary>
        Public Property PictureTitle() As String
            Get
                Return m_pictureTitle
            End Get
            Set(ByVal value As String)
                m_pictureTitle = value
            End Set
        End Property
        ''' <summary>
        ''' Date filters associated with picture files. 
        ''' Possible picture date filters are represented by PictureDateFilter enumeration.
        ''' Searching is not performed according to date if value for PictureDateFilter enumeration is “None”. 
        ''' Default value is “None”.
        ''' </summary>
        Public Property PictureDateFilter() As PictureDateFilter
            Get
                Return m_pictureDateFilter
            End Get
            Set(ByVal value As PictureDateFilter)
                m_pictureDateFilter = value
            End Set
        End Property
#End Region

#Region "constructor"
        ''' <summary>
        '''  Initializes search criteria for picture search. 
        ''' </summary>
        Public Sub New(ByVal searchCriteria As SearchCriteria, ByVal pictureName As String, _
                       ByVal pictureTag As String, ByVal pictureTitle As String, _
                       ByVal pictureDateFilter As PictureDateFilter)
            Me.PictureName = pictureName
            Me.PictureTag = pictureTag
            Me.PictureTitle = pictureTitle
            Me.PictureDateFilter = pictureDateFilter
            If searchCriteria IsNot Nothing Then
                Me.[Date] = searchCriteria.[Date]
                Me.DateCompareOption = searchCriteria.DateCompareOption
                Me.Extension = searchCriteria.Extension
                Me.Size = searchCriteria.Size
                Me.SearchLocation = searchCriteria.SearchLocation
                Me.SizeCompareOption = searchCriteria.SizeCompareOption
            Else
                Me.[Date] = DateTime.Now
            End If
        End Sub
        ''' <summary>
        '''  Initializes default search criteria for picture search. 
        ''' </summary>
        Public Sub New()
            Me.[Date] = DateTime.Now
        End Sub
#End Region
    End Class
    ''' <summary>
    ''' This class contains properties related to music. 
    ''' This is used to specify music file search criteria.
    '''  If value for any of the search criteria is not specified then music file is not searched according to that parameter. 
    ''' Aiff, av, asx, mp2, mp3, m3u, mp2v, ost, spc, wma, wav, wax, wmd, wm, wmx, wmdb are standared type supported by desktop search api.
    ''' </summary>
    Public Class MusicSearchCriteria
        Inherits SearchCriteria
#Region "Private Members"
        ''' <summary>
        '''  Specifies name of music file.
        ''' </summary>
        Private m_musicTitle As String
        ''' <summary>
        '''  Specifies name of music artist.
        ''' </summary>
        Private m_artistName As String
        ''' <summary>
        ''' Specifies name of music album.
        ''' </summary>
        Private m_albumName As String
        '''   <summary>
        ''' Specifies date filters associated with music file
        ''' </summary>
        Private m_musicDateFilter As MusicDateFilter
#End Region

#Region "Public Properties"
        ''' <summary>
        '''  Title of music file.
        ''' </summary>
        Public Property MusicTitle() As String
            Get
                Return m_musicTitle
            End Get
            Set(ByVal value As String)
                m_musicTitle = value
            End Set
        End Property
        ''' <summary>
        '''  Name of music artist. 
        ''' </summary>
        Public Property ArtistName() As String
            Get
                Return m_artistName
            End Get
            Set(ByVal value As String)
                m_artistName = value
            End Set
        End Property
        ''' <summary>
        '''  Name of music album.
        ''' </summary>
        Public Property AlbumName() As String
            Get
                Return m_albumName
            End Get
            Set(ByVal value As String)
                m_albumName = value
            End Set
        End Property
        ''' <summary>
        ''' Date filters associated with music files. 
        ''' Possible music date filters are represented by MusicDateFilter enumeration.
        ''' Searching is not performed according to date if value for MusicDateFilter enumeration is “None”. 
        ''' Default value is “None”.
        ''' </summary>
        Public Property MusicDateFilter() As MusicDateFilter
            Get
                Return m_musicDateFilter
            End Get
            Set(ByVal value As MusicDateFilter)
                m_musicDateFilter = value
            End Set
        End Property
#End Region

#Region "Constructors"
        ''' <summary>
        '''  Initializes search criteria for music search. 
        ''' </summary>
        Public Sub New(ByVal searchCriteria As SearchCriteria, ByVal albumName As String, _
                       ByVal artistName As String, ByVal musicTitle As String, _
                       ByVal musicDateFilter As MusicDateFilter)
            Me.AlbumName = albumName
            Me.ArtistName = artistName
            Me.MusicTitle = musicTitle
            Me.MusicDateFilter = musicDateFilter
            If searchCriteria IsNot Nothing Then
                Me.[Date] = searchCriteria.[Date]
                Me.DateCompareOption = searchCriteria.DateCompareOption
                Me.Extension = searchCriteria.Extension
                Me.Size = searchCriteria.Size
                Me.SearchLocation = searchCriteria.SearchLocation
                Me.SizeCompareOption = searchCriteria.SizeCompareOption
            Else
                Me.[Date] = DateTime.Now
            End If
        End Sub
        ''' <summary>
        '''  Initializes default search criteria for music search. 
        ''' </summary>
        Public Sub New()
            Me.[Date] = DateTime.Now
        End Sub
#End Region
    End Class
    ''' <summary>
    ''' Represents file information.
    ''' </summary>
    Public Class FileInfo
#Region "Private Members"
        ''' <summary>
        ''' Name of file.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Date when the file was last modified. 
        ''' </summary>
        Private m_dateModified As DateTime
        ''' <summary>
        ''' Date when the file was created. 
        ''' </summary>
        Private m_dateCreated As DateTime
        ''' <summary>
        ''' Location of file.
        ''' </summary>
        Private m_searchLocation As String
        ''' <summary>
        ''' Title of file.
        ''' </summary>
        Private m_title As String
        ''' <summary>
        ''' Author of file.
        ''' </summary>
        Private m_author As List(Of String)
        ''' <summary>
        ''' Attributes of file.
        ''' </summary>
        Private m_attributes As FileAttributes
        ''' <summary>
        ''' Actual size of the file in byte.
        ''' </summary>
        Private m_size As UInteger
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Name of file.
        ''' </summary>
        Public Property Name() As String
            Get
                Return m_name
            End Get
            Set(ByVal value As String)
                m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Date when the file was last modified.
        ''' </summary>
        Public Property DateModified() As DateTime
            Get
                Return m_dateModified
            End Get
            Set(ByVal value As DateTime)
                m_dateModified = value
            End Set
        End Property
        ''' <summary>
        ''' Date when the file was created. 
        ''' </summary>
        Public Property DateCreated() As DateTime
            Get
                Return m_dateCreated
            End Get
            Set(ByVal value As DateTime)
                m_dateCreated = value
            End Set
        End Property
        ''' <summary>
        ''' Location of file.
        ''' </summary>
        Public Property SearchLocation() As String
            Get
                Return m_searchLocation
            End Get
            Set(ByVal value As String)
                m_searchLocation = value
            End Set
        End Property
        ''' <summary>
        ''' Actual size of the file in byte.
        ''' </summary>
        Public Property Size() As UInteger
            Get
                Return m_size
            End Get
            Set(ByVal value As UInteger)
                m_size = value
            End Set
        End Property
        ''' <summary>
        ''' Title of file.
        ''' </summary>
        Public Property Title() As String
            Get
                Return m_title
            End Get
            Set(ByVal value As String)
                m_title = value
            End Set
        End Property
        ''' <summary>
        ''' Author of file.
        ''' </summary>
        Public Property Author() As List(Of String)
            Get
                Return m_author
            End Get
            Set(ByVal value As List(Of String))
                m_author = value
            End Set
        End Property
        ''' <summary>
        ''' Attributes of file.
        ''' </summary>
        Public Property Attributes() As FileAttributes
            Get
                Return m_attributes
            End Get
            Set(ByVal value As FileAttributes)
                m_attributes = value
            End Set
        End Property
#End Region
    End Class
    ''' <summary>
    ''' Represent music items information.
    ''' </summary>
    Public Class MusicInfo
#Region "Private Member"
        ''' <summary>
        ''' Name of music file.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Name of album.
        ''' </summary>
        Private m_album As String
        ''' <summary>
        ''' Name of artists.
        ''' </summary>
        Private m_artists As List(Of String)
        ''' <summary>
        ''' Actual size of the music file in byte.
        ''' </summary>
        Private m_size As UInteger
        ''' <summary>
        ''' Rating of music file.
        ''' </summary>
        Private m_rating As UInteger
        ''' <summary>
        ''' Location of music file.
        ''' </summary>
        Private m_searchLocation As String
        ''' <summary>
        ''' Attributes of file.
        ''' </summary>
        Private m_attributes As FileAttributes
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Name of music file.
        ''' </summary>
        Public Property Name() As String
            Get
                Return m_name
            End Get
            Set(ByVal value As String)
                m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Name of album.
        ''' </summary>
        Public Property Album() As String
            Get
                Return m_album
            End Get
            Set(ByVal value As String)
                m_album = value
            End Set
        End Property
        ''' <summary>
        ''' Location of music file.
        ''' </summary>
        Public Property SearchLocation() As String
            Get
                Return m_searchLocation
            End Get
            Set(ByVal value As String)
                m_searchLocation = value
            End Set
        End Property
        ''' <summary>
        ''' Name of artists.
        ''' </summary>
        Public Property Artists() As List(Of String)
            Get
                Return m_artists
            End Get
            Set(ByVal value As List(Of String))
                m_artists = value
            End Set
        End Property
        ''' <summary>
        ''' Actual size of the music file in byte.
        ''' </summary>
        Public Property Size() As UInteger
            Get
                Return m_size
            End Get
            Set(ByVal value As UInteger)
                m_size = value
            End Set
        End Property
        ''' <summary>
        ''' Rating of music file.
        ''' </summary>
        Public Property Rating() As UInteger
            Get
                Return m_rating
            End Get
            Set(ByVal value As UInteger)
                m_rating = value
            End Set
        End Property
        ''' <summary>
        ''' Attributes of music file.
        ''' </summary>
        Public Property Attributes() As FileAttributes
            Get
                Return m_attributes
            End Get
            Set(ByVal value As FileAttributes)
                m_attributes = value
            End Set
        End Property
#End Region
    End Class
    ''' <summary>
    ''' Represents information related to email.
    ''' </summary>
    Public Class EmailInfo
#Region "Private Member"
        ''' <summary>
        ''' Represents email address of sender of the email.
        ''' </summary>
        Private m_from As String
        ''' <summary>
        ''' Represents subject of email.
        ''' </summary>
        Private m_subject As String
        ''' <summary>
        ''' Represents the date when email was received.
        ''' </summary>
        Private m_dateReceived As DateTime
        ''' <summary>
        ''' Represents email address in ‘To’ list of the email. 
        ''' </summary>
        Private m_toList As List(Of String)
        ''' <summary>
        ''' Represents actual size of the email in byte.
        ''' </summary>
        Private m_size As UInteger
        ''' <summary>
        ''' Specifies whether email have attachments or not.
        ''' </summary>
        Private m_hasAttachments As Boolean
        ''' <summary>
        ''' List of attachments assoiated with email.
        ''' </summary>
        Private m_attachments As List(Of String)
        ''' <summary>
        ''' Priority associated with email.
        ''' </summary>
        Private m_priority As EmailPriority
#End Region

#Region "Public Properties"
        ''' <summary>
        ''' Represents email address of sender of the email.
        ''' </summary>
        Public Property [From]() As String
            Get
                Return m_from
            End Get
            Set(ByVal value As String)
                m_from = value
            End Set
        End Property
        ''' <summary>
        ''' Represents the string to be searched in the subject field of an email.
        ''' </summary>
        Public Property Subject() As String
            Get
                Return m_subject
            End Get
            Set(ByVal value As String)
                m_subject = value
            End Set
        End Property
        ''' <summary>
        ''' Represents the date when email was received.
        ''' </summary>
        Public Property DateReceived() As DateTime
            Get
                Return m_dateReceived
            End Get
            Set(ByVal value As DateTime)
                m_dateReceived = value
            End Set
        End Property
        ''' <summary>
        ''' Represents email address in ‘To’ list of the email
        ''' </summary>
        Public Property ToList() As List(Of String)
            Get
                Return m_toList
            End Get
            Set(ByVal value As List(Of String))
                m_toList = value
            End Set
        End Property
        ''' <summary>
        ''' Represents actual size of the email in byte.
        ''' </summary>
        Public Property Size() As UInteger
            Get
                Return m_size
            End Get
            Set(ByVal value As UInteger)
                m_size = value
            End Set
        End Property
        ''' <summary>
        ''' Specifies whether email have attachments or not.
        ''' </summary>
        Public Property HasAttachments() As Boolean
            Get
                Return m_hasAttachments
            End Get
            Set(ByVal value As Boolean)
                m_hasAttachments = value
            End Set
        End Property
        ''' <summary>
        ''' List of attachments assoiated with email.
        ''' </summary>
        Public Property Attachments() As List(Of String)
            Get
                Return m_attachments
            End Get
            Set(ByVal value As List(Of String))
                m_attachments = value
            End Set
        End Property
        ''' <summary>
        ''' Priority associated with email.
        ''' </summary>
        Public Property Priority() As EmailPriority
            Get
                Return m_priority
            End Get
            Set(ByVal value As EmailPriority)
                m_priority = value
            End Set
        End Property
#End Region
    End Class
    ''' <summary>
    ''' Represents information related to pictures.
    ''' </summary>
    Public Class PictureInfo
#Region "Private Member"
        ''' <summary> 
        ''' Name of picture file.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Specifies date when picture file was taken. 
        ''' </summary>
        Private m_dateTaken As DateTime
        ''' <summary>
        ''' Location of picture file.
        ''' </summary>
        Private m_searchLocation As String
        ''' <summary>
        ''' Tags of picture file.
        ''' </summary>
        Private m_tags As List(Of String)
        ''' <summary>
        ''' Actual size of the picture files in byte.
        ''' </summary>
        Private m_size As UInteger
        ''' <summary>
        ''' Rating associated with picture file.
        ''' </summary>
        Private m_rating As UInteger
        ''' <summary>
        ''' Attributes of file.
        ''' </summary>
        Private m_attributes As FileAttributes
#End Region

#Region "Public Properties"
        ''' <summary> 
        ''' Name of picture file.
        ''' </summary>
        Public Property Name() As String
            Get
                Return m_name
            End Get
            Set(ByVal value As String)
                m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Specifies date when picture file was taken. 
        ''' If date when picture file was taken is not associated with picture file then default date “01-01-0001” will be displayed.
        ''' </summary>
        Public Property DateTaken() As DateTime
            Get
                Return m_dateTaken
            End Get
            Set(ByVal value As DateTime)
                m_dateTaken = value
            End Set
        End Property
        ''' <summary>
        ''' Location of picture file.
        ''' </summary>
        Public Property SearchLocation() As String
            Get
                Return m_searchLocation
            End Get
            Set(ByVal value As String)
                m_searchLocation = value
            End Set
        End Property
        ''' <summary>
        ''' List of tags.
        ''' </summary>
        Public Property Tags() As List(Of String)
            Get
                Return m_tags
            End Get
            Set(ByVal value As List(Of String))
                m_tags = value
            End Set
        End Property
        ''' <summary>
        ''' Actual size of the picture files in byte.
        ''' </summary>
        Public Property Size() As UInteger
            Get
                Return m_size
            End Get
            Set(ByVal value As UInteger)
                m_size = value
            End Set
        End Property
        ''' <summary>
        ''' Rating associated with picture file.
        ''' </summary>
        Public Property Rating() As UInteger
            Get
                Return m_rating
            End Get
            Set(ByVal value As UInteger)
                m_rating = value
            End Set
        End Property
        ''' <summary>
        ''' Attributes of picture file.
        ''' </summary>
        Public Property Attributes() As FileAttributes
            Get
                Return m_attributes
            End Get
            Set(ByVal value As FileAttributes)
                m_attributes = value
            End Set
        End Property
#End Region
    End Class
#End Region
End Namespace
